package com.globallogic.training.javase.university.curriculum;

import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import com.globallogic.training.javase.university.member.Group;
import com.globallogic.training.javase.university.member.Instructor;
import com.globallogic.training.javase.university.schedule.Auditorium;

/**
 * Abstract class to hold collective information about university activity, like
 * topic and instructor.
 * 
 * @author Artem.Zeltinsh
 */
public abstract class Activity {

	private String id;

	private String topic;

	private Auditorium auditorium;

	private Subject subject;

	Activity(String id, Subject subject, String topic) {

		if (StringUtils.isBlank(id)) {
			throw new IllegalArgumentException("Input 'id' should not be empty.");
		}

		if (StringUtils.isBlank(topic)) {
			throw new IllegalArgumentException("Input 'topic' should not be empty.");
		}

		if (subject == null) {
			throw new IllegalArgumentException(
					"Input 'subject' should not be empty.");
		}

		this.id = id;
		this.subject = subject;
		this.topic = topic;
	}

	public String getId() {
		return id;
	}

	public String getTopic() {
		return topic;
	}

	public Instructor getInstructor() {
		return subject.getDefaultInstructor();
	}

	public Auditorium getAuditorium() {
		return auditorium;
	}

	public void setAuditorium(Auditorium auditorium) {
		this.auditorium = auditorium;
	}

	public Subject getSubject() {
		return subject;
	}
	
	public Set<Group> getEnrolledGroups() {
		return subject.getGroups();
	}

	@Override
	public int hashCode() {
		return 1 * 31 + id.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(this.getClass() != obj.getClass())) {
			return false;
		}

		Activity other = (Activity) obj;
		if (id.equals(other.id)) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return id + " " + topic;
	}
}